﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace TSPquestEDITOR
{
    public partial class basic_info : Form
    {
        public void load_primary_quest_info()
        {
            SqlConnection qCon = new SqlConnection(connectionString);

            bgw.ReportProgress(1, "READING PRIMARY QUEST INFO");

            if (!string.IsNullOrEmpty(multi_quest_search_return_id))
            {

                if (multi_quest_search_return_id != "0")
                {
                    fin_qID = Convert.ToInt32(multi_quest_search_return_id);
                }
                else
                {
                    MessageBox.Show("Fatal Error: 1");
                    //1: The multi_quest_search_return_id was NOT given on the form2/3 close
                }
            }

            SqlCommand command = new SqlCommand(
            "SELECT TOP(1) id, text_id_quest, limit_level, limit_job_level, limit_max_level, limit_deva, limit_asura, limit_gaia, time_limit_type, time_limit, type, value1, value2, value3, value4, value5, exp, jp, gold, holicpoint FROM  QuestResource WHERE id = '" + fin_qID + "'",
            qCon);
            qCon.Open();

            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    quest_id_val = reader.GetInt32(0);
                    quest_name_id_val = reader.GetInt32(1);
                    quest_level_req_val = reader.GetInt32(2);
                    quest_limit_job_lv_val = reader.GetInt32(3);
                    quest_limit_max_lv_val = reader.GetInt32(4);
                    limit_deva_val = Convert.ToInt32(reader.GetString(5));
                    limit_asura_val = Convert.ToInt32(reader.GetString(6));
                    limit_gaia_val = Convert.ToInt32(reader.GetString(7));
                    quest_time_type_val = Convert.ToInt32(reader.GetString(8));
                    quest_time_limit_val = reader.GetInt32(9);
                    //Set Temp Quest Val 
                    int quest_type_id_val = reader.GetInt32(10);
                    //Start Quest Type Translation
                    if (quest_type_id_val == 100)
                    {
                        quest_type_val = "MISC";
                    }
                    else if (quest_type_id_val == 101)
                    {
                        quest_type_val = "KILL_TOTAL";
                    }
                    else if (quest_type_id_val == 102)
                    {
                        quest_type_val = "KILL_INDIVIDUAL";
                    }
                    else if (quest_type_id_val == 103)
                    {
                        quest_type_val = "COLLECT";
                    }
                    else if (quest_type_id_val == 106)
                    {
                        quest_type_val = "HUNT_ITEM";
                    }
                    else if (quest_type_id_val == 107)
                    {
                        quest_type_val = "HUNT_ITEM_FROM_ANY_MONSTER";
                    }
                    else if (quest_type_id_val == 201)
                    {
                        quest_type_val = "LEARN_SKILL";
                    }
                    else if (quest_type_id_val == 301)
                    {
                        quest_type_val = "UPGRADE_ITEM";
                    }
                    else if (quest_type_id_val == 401)
                    {
                        quest_type_val = "CONTACT";
                    }
                    else if (quest_type_id_val == 501)
                    {
                        quest_type_val = "JOB_LEVEL";
                    }
                    else if (quest_type_id_val == 601)
                    {
                        quest_type_val = "PARAMETER";
                    }
                    else if (quest_type_id_val == 901)
                    {
                        quest_type_val = "RANDOM_KILL_INDIVIDUAL";
                    }
                    else if (quest_type_id_val == 902)
                    {
                        quest_type_val = "RANDOM_COLLECT";
                    }
                    quest_value1_val = reader.GetInt32(11);
                    quest_value2_val = reader.GetInt32(12);
                    quest_value3_val = reader.GetInt32(13);
                    quest_value4_val = reader.GetInt32(14);
                    quest_value5_val = reader.GetInt32(15);
                    quest_exp_val = reader.GetInt64(16);
                    quest_jp_val = reader.GetInt32(17);
                    quest_gold_val = reader.GetInt32(18);
                    quest_holicpoint_val = reader.GetInt32(19);
                }
            }

            bgw.ReportProgress(11, "READING QUEST NPC INFO");
            //Execute NPC Info Loader
            load_quest_npc_info();

            bgw.ReportProgress(31, "READING QUEST OBJECTIVES");
            //Execute Objective Loader
            load_quest_objectives();

            bgw.ReportProgress(41, "READING QUEST REWARDS ");
            //Execute Reward Loader
            load_quest_rewards();

            bgw.ReportProgress(51, "READING QUEST RELATED STRINGS ");
            //Now lets load Quest Strings
            load_quest_strings();

            bgw.ReportProgress(61, "READING QUEST DESCRIPTION INFO");
            //Lets Load Start Vals First
            load_start_desc_id();

            bgw.ReportProgress(71, "READING QUEST DESCRIPTION INFO ");
            //Now lets load End Vals
            load_end_desc_id();

            bgw.ReportProgress(81, "PROCESSING...PLEASE WAIT");
            //Translate Strings
            translate_strings();

            update_ui_txt(1, "");

            reader.Close();
            qCon.Close();
        } 
     }
}
